tmp_swj <-
    foreach(i = colnames(df_swj)[-1], .combine = cbind) %do% {
        tmp_df <- data.frame(term = df_swj[, i], group = df_swj$id)
        # t1 <- wilcox_test(tmp_df, term ~ group)
        # t2 <- t1$p
        # names(t2) <- paste0(t1$group1, "-", t1$group2)
        # label <- multcompLetters(t2, rev = T)
        tmp_md <- group_by(tmp_df, group) %>%
            summarise(i = paste0(
                sprintf("%0.2f", mean(term)),
                t001,
                sprintf("%0.2f", sd(term))
            ))
        tmp_out <- data.frame(
            # term = paste0(tmp_md$i, label$Letters[tmp_md$group]),
            term = tmp_md$i,
            row.names = tmp_md$group
        )
        colnames(tmp_out) <- i
        return(tmp_out)
    }
# group_by(tmp_df, group) %>%
#     summarise_all(~ paste0(
#         sprintf("%0.2f", mean(.)),
#         t001,
#         sprintf("%0.2f", sd(.))
#     ))
yywrite(tmp_swj, "tmp.tsv", row.names = T)

tmp_swj2 <-
    foreach(i = colnames(df_swj)[-1], .combine = cbind) %do% {
        tmp_df <- data.frame(term = df_swj[, i], group = df_swj$id)
        tmp_md <- group_by(tmp_df, group) %>%
            summarise(i = sd(term) / mean(term))
        tmp_out <- data.frame(
            term = tmp_md$i,
            row.names = tmp_md$group
        )
        colnames(tmp_out) <- i
        return(tmp_out)
    }
tmp_swj3 <-
    foreach(i = colnames(df_swj)[-1], .combine = cbind) %do% {
        tmp_df <- data.frame(term = df_swj[, i], group = str_sub(df_swj$id, 1, 1))
        tmp_md <- group_by(tmp_df, group) %>%
            summarise(i = sd(term) / mean(term))
        tmp_out <- data.frame(
            # term = paste0(tmp_md$i, label$Letters[tmp_md$group]),
            term = tmp_md$i,
            row.names = tmp_md$group
        )
        colnames(tmp_out) <- i
        return(tmp_out)
    }

rbind(tmp_swj2, tmp_swj3) %>% yywrite("tmp.tsv", row.names = T)


